package com.zide.link.service.impl;

import java.util.Arrays;
import java.util.List;
import com.zide.common.core.domain.PageResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zide.common.core.vo.CommonParamIdVO;
import com.zide.common.utils.DateUtils;
import com.zide.link.domain.po.LinkWeb;
import com.zide.link.domain.vo.result.LinkWebResultVO;
import com.zide.link.domain.vo.save.LinkSearchSaveVO;
import com.zide.link.domain.vo.save.LinkWebSaveVO;
import com.zide.link.domain.vo.search.LinkWebSearchVO;
import com.zide.link.mapper.LinkWebMapper;
import com.zide.link.service.ILinkWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 外链网站Service业务层处理
 * 
 * @author zide
 * @date 2024-05-10
 */
@Slf4j
@Service
public class LinkWebServiceImpl implements ILinkWebService {
    @Autowired
    private LinkWebMapper linkWebMapper;

    /**
     * 查询外链网站列表
     */
    @Override
    public PageResult<LinkWebResultVO> searchLinkWebPageList(LinkWebSearchVO searchVO) {
        PageResult<LinkWeb> dbPageResult = linkWebMapper.selectPage(searchVO);
        List<LinkWebResultVO> resultList = BeanUtil.copyToList(dbPageResult.getList(),LinkWebResultVO.class);
        PageResult<LinkWebResultVO> result = new PageResult<>();
        result.setTotal(dbPageResult.getTotal());
        result.setList(resultList);
        return result;
    }

    /**
     * 查询外链网站详情
     */
    @Override
    public LinkWebResultVO selectLinkWebById(Long id) {
            LinkWeb dbInfo = linkWebMapper.selectById(id);
            LinkWebResultVO result = BeanUtil.copyProperties(dbInfo,LinkWebResultVO.class);
        return result;
    }

    /**
     * 新增外链网站
     */
    @Override
    public int saveLinkWeb(LinkWebSaveVO saveVO) {
        LinkWeb insertBean = BeanUtil.copyProperties(saveVO,LinkWeb.class);
        return linkWebMapper.insert(insertBean);
    }

    /**
     * 修改外链网站
     */
    @Override
    public int updateLinkWeb(LinkWebSaveVO saveVO) {
        LinkWeb updateBean = BeanUtil.copyProperties(saveVO,LinkWeb.class);
        return linkWebMapper.updateById(updateBean);
    }

    /**
     * 批量删除外链网站
     */
    @Override
    public int removeLinkWebByIds(CommonParamIdVO idVO) {
        if(ArrayUtil.isNotEmpty(idVO.getIds())) {
            return linkWebMapper.deleteBatchIds(Arrays.asList(idVO.getIds()));
        }else {
            return linkWebMapper.deleteById(idVO.getId());
        }

    }

    @Override
    public int updateStatus(LinkSearchSaveVO saveVO) {
        LinkWeb updateBean = BeanUtil.copyProperties(saveVO,LinkWeb.class);
        return linkWebMapper.updateById(updateBean);
    }
}
